package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.CoreReminderClassificationDto;
import com.corechina.apex_osswords.domain.entity.CoreReminderClassification;
import com.corechina.apex_osswords.service.ICoreIReminderClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 提醒分类配置表 前端控制器
 * </p>
 *
 * @author fyh
 * @since 2024-02-19
 */
@Api(tags = "提醒分类")
@RestController
@RequestMapping("/core/reminderClassification")
public class CoreReminderClassificationController {
    @Autowired
    private ICoreIReminderClassificationService ICoreIReminderClassificationService;

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return Response.ok(ICoreIReminderClassificationService.getById(id));
    }

    @ApiOperation("新增")
    @SysLog("新增项目/设备的提醒")
    @PostMapping("/add")
    public Response add(@RequestBody CoreReminderClassificationDto coreReminderClassificationDto) {
        return ICoreIReminderClassificationService.add(coreReminderClassificationDto);
    }

    @ApiOperation("编辑")
    @SysLog("编辑项目/设备的提醒")
    @PutMapping("/update")
    public Response update(@RequestBody CoreReminderClassification coreReminderClassification) {
        coreReminderClassification.setEnterpriseId(ShiroUtils.getEnterpriseId());
        coreReminderClassification.setCreator(ShiroUtils.getUserId());
        if (ICoreIReminderClassificationService.updateById(coreReminderClassification)){
            return Response.ok("编辑成功");
        }
        return Response.error();
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(Integer classifying, String name, Integer creator, Integer enterpriseId, Integer pageIndex, Integer pageSize) {
        return ICoreIReminderClassificationService.getList(classifying, name, creator, enterpriseId, pageIndex, pageSize);
    }


    @SysLog("删除项目/设备的提醒")
    @ApiOperation("删除")
    @DeleteMapping("/del")
    public Response del(String name){
        Integer id = ICoreIReminderClassificationService.nameSearch(name);
        if(ICoreIReminderClassificationService.removeById(id)) {
            return Response.ok("删除提醒成功");
        }
            return Response.error();
    }

}

